import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions, Response} from '@angular/http';
import { Observable } from 'rxjs';
import 'rxjs/add/operator/map';

import { AuthenticationService } from './authemtication.service';
import { User } from '../_models/user';


@Injectable()
export class UserService {
    constructor(private http: Http, private authemticationService: AuthenticationService){}
    getUsers(): Observable<User[]> {
        let headers = new Headers({'Authorization': 'Bearer' + this.authemticationService.token});
        let options = new RequestOptions({headers: headers});
        //get users from api 
        var url = "http://127.0.0.1:3030/users/queryAll"
        return this.http.get(url,options)
                .map((response: Response)=>{
                    return response.json();
                })
    }
}
